<?php 
/*
 module:		简历证书
 create_time:	2024-03-13 11:17:34
 author:		
 contact:		
*/

namespace app\api\controller;

use app\api\service\ResumecredentService;
use app\api\model\Resumecredent as ResumecredentModel;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Log;

class Resumecredent extends Common {




 /*start*/
    /**
     * @api {get} /Resumecredent/index 01、首页数据列表
     */
    function index()
    {
        $limit = $this->request->get('limit', 20, 'intval');
        $page = $this->request->get('page', 1, 'intval');

        $where = [];
        $uid = $this->request->uid;
        $where['pid']  = \app\api\model\Resume::where("uid", $uid)->order("id DESC")->value("id");
        $where['uid'] =$uid;
        $field = '*';
        $orderby = 'id desc';

        $res = ResumecredentService::indexList(formatWhere($where), $field, $orderby, $limit, $page);
        if (!empty($res["list"])) {
            $list = $res["list"];
            foreach ($list as &$item) {
                $item = $this->getItem($item);
            }
            $res["list"] = $list;
        }
        return $this->ajaxReturn($this->successCode, '返回成功', htmlOutList($res));
    }

    /**
     * @api {post} /Resumecredent/add 02、添加
     */
    function add()
    {
        $postField = 'name,year,month,images';
        $data = $this->request->only(explode(',', $postField), 'post', null);
        $uid = $this->request->uid;
        $data['pid']  = \app\api\model\Resume::where("uid", $uid)->order("id DESC")->value("id");
        $data['uid'] =$uid;
        $res = ResumecredentService::add($data);
        return $this->ajaxReturn($this->successCode, '操作成功', $res);
    }
    /**
     * @api {post} /Resumecredent/update 03、修改
     */
    function update()
    {
        $postField = 'id,name,year,month,images';
        $data = $this->request->only(explode(',', $postField), 'post', null);
        if (empty($data['id'])) {
            throw new ValidateException('参数错误');
        }
        $where['id'] = $data['id'];
        $res = ResumecredentService::update($where, $data);
        return $this->ajaxReturn($this->successCode, '操作成功',$res);
    }

    /**
     * @api {post} /Resumecredent/delete 04、删除
     */
    function delete()
    {
        $idx = $this->request->post('id', '', 'serach_in');
        if (empty($idx)) {
            throw new ValidateException('参数错误');
        }
        $data['id'] = explode(',', $idx);
        try {
            ResumecredentModel::destroy($data, true);
        } catch (\Exception $e) {
            abort(config('my.error_log_code'), $e->getMessage());
        }
        return $this->ajaxReturn($this->successCode, '操作成功');
    }
    /**
     * @api {get} /Resumecredent/view 05、查看详情
     */
    function view(){
        $data['id'] = $this->request->get('id','','serach_in');
        $field='id,images,month,year,name';
        $item  =ResumecredentModel::field($field)->where($data)->findOrEmpty()->toArray();
        $item=$this->getItem($item);
        return $this->ajaxReturn($this->successCode,'返回成功',$item);
    }
    public function getItem($item)
    {
        if (!empty($item["images"])) {
            if (!array_key_exists('scheme', parse_url($item["images"])) && !empty($item["images"])) {
                $item["images"] = "https://www.lianhezhaopin.com/data/upload/company_logo/". $item["images"];
            }

        }
        return $item;
    }
    /*end*/



}

